﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace Common
{
    public class xmlConfig
    {
        public xmlConfig()
        {

        }
        public static string AppPath()
        {
            return AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[]
            {
                '\\'
            }) + '\\';
        }
        public static string ReadValue(string nodeName)
        {
            string rel = "";
            try
            {
                XmlDocument xd = new XmlDocument();
                xd.Load(lIniOperate.IniAppPath() + "logxml.xml");
                XmlNode rootNode = xd.SelectSingleNode("ISLOG");
                if (rootNode.ChildNodes.Count > 0)
                {
                    foreach (XmlNode n in rootNode.ChildNodes)
                    {
                        if (n.Name == nodeName)
                            rel = n.InnerText;
                    }
                }
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
            return rel;
        }
        public static bool WriteValue(string nodeName, string nodeValue)
        {
            try
            {
                string xmlFiles = lIniOperate.IniAppPath() + "logxml.xml";
                XmlDocument xd = new XmlDocument();
                xd.Load(xmlFiles);
                XmlNode rootNode = xd.SelectSingleNode("ISLOG");
                if (rootNode.ChildNodes.Count > 0)
                {
                    foreach (XmlNode n in rootNode.ChildNodes)
                    {
                        if (n.Name == nodeName)
                            n.InnerText = nodeValue;
                    }
                }
                xd.Save(xmlFiles);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return false;
            }
            return true;
        }
    }
}
